﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ValidationFramework.Configuration.Fluent;
using System.IO;
using System.Xml;
using System.Reflection;
using ValidationFramework.Configuration.Xml;

namespace ValidationFramework.Configuration
{
	public class InitializationExpression : IInitializationExpression
	{
		private IParserRepository _parserRepository;
		bool _loadFromAppConfig;
		bool _localizationEnabled;
		bool _ignoreAttribute;

		IErrorMessageProvider _errorMessageProvider;

		public IParserRepository GetParserRepository()
		{
			return _parserRepository;
		}

		public InitializationExpression()
		{
			_parserRepository = new ParserRepository();
			_localizationEnabled = false;

			_loadFromAppConfig = false;

#if (WindowsCE || SILVERLIGHT)
			_loadFromAppConfig = false;
#endif
		}

		// --- IInitializationExpression Members

		public void EnableLocalization(IErrorMessageProvider errorMessageProvider)
		{
			_localizationEnabled = true;
			_errorMessageProvider = errorMessageProvider;
		}
		public void EnableLocalization()
		{
			_localizationEnabled = true;
			_errorMessageProvider = null;
		}

		public void RegisterReader<TValidator>(ValidationFramework.Configuration.Xml.ISpecificationXmlParser reader)
		{
			RegisterReader(typeof(TValidator), reader);
		}
		public void RegisterReader(Type validatorType, ISpecificationXmlParser reader)
		{
			_parserRepository.AddParser(validatorType, reader);
		}

#if (!WindowsCE && !SILVERLIGHT)
		public bool LoadConfigurationFromAppConfig
		{
			get { return _loadFromAppConfig; }
			set { _loadFromAppConfig = value; }
		}
#endif

		public bool IgnoreAttributes
		{
			get { return _ignoreAttribute; }
			set { _ignoreAttribute = value; }
		}

	}
}
